package com.jungle.sp.daily.feature.d1_pattern_matching;

/**
 * @author Jungle
 * @create 2024-07-13 23:25
 */
public class Demo1 {
    public static void main(String[] args) {

        // judge(100);
        // judge1(100);

        String ou = formatter2(null);
        System.out.println(ou);
    }

    public static void judge(Object o) {
        if (o instanceof String s) {
            System.out.println(s.length());
        }

    }

    public static void judge1(Object o) {
        if (o instanceof Integer i) {
            System.out.println(i + 100);
        }

    }

    /**
     * switch表达式
     */
    public static String formatter2(Object o) {
        return switch (o) {
            case null -> null;
            case Integer i -> String.format("整数：%d", i);
            case Double d -> String.format("%.2f", d);
            case Long l -> String.format("长整数：%d", l);
            default -> "未知类型";
        };

    }
}
